﻿//
// XN4SL - Xna Framework for Silverlight.
//
using System;
using System.Reflection;
using System.Collections.Generic;

namespace Xn4Sl.Framework.Media
{
    /// <summary>
    /// Provides methods and properties to access and control the queue of playing songs.
    /// </summary>
    public sealed class MediaQueue
    {
        /// <summary>
        /// Songs queue.
        /// </summary>
        private List<Song> songs = new List<Song>();

        /// <summary>
        /// Adds Song to the queue.
        /// </summary>
        /// <param name="song">Song to add.</param>
        public void Add(Song song)
        {
            this.songs.Add(song);

            if (this.activeSong == null)
            {
                this.activeSong = song;
            }
        }

        /// <summary>
        /// Gets the current Song in the queue of playing songs.
        /// </summary>
        private Song activeSong;
        public Song ActiveSong
        {
            get
            {
                return this.activeSong;
            }
        }

        /// <summary>
        /// Gets or sets the index of the current (active) song in the queue of playing songs.
        /// </summary>
        public int ActiveSongIndex 
        {
            get
            {
                if (this.activeSong == null)
                {
                    return -1;
                }
                else
                    return this.songs.IndexOf(this.ActiveSong);
            }
            set
            {
                if(value > 0 && value < this.songs.Count)
                {
                    this.activeSong = this.songs[value];
                }
            }
        }

        /// <summary>
        /// Gets the count of songs in the queue.
        /// </summary>
        public int Count
        {
            get
            {
                return this.songs.Count;
            }
        }

        /// <summary>
        /// Gets the Song at the specified index in the queue.
        /// </summary>
        /// <param name="index"></param>
        /// <returns>A new Song representing the song at the specified index in this queue.</returns>
        public Song this[int index]
        {
            get
            {
                if (index < this.songs.Count)
                {
                    return this.songs[index];
                }
                else
                    return null;
            }
        }
    }
}
